﻿(function ($) {

    app.modals.CreateProductModal = function () {
        var _productService = abp.services.app.product;
        var _$productForm = null;

        var _modalManager;
        this.init = function (modalManager) {
            _modalManager = modalManager;
            //取出Form表单
            _$productForm = _modalManager.getModal().find('form[name=ProductForm]');
        };

        this.save = function () {
            if (!_$productForm.valid()) {
                return;
            }
            //序列化参数
            var product = _$productForm.serializeFormToObject();
            _modalManager.setBusy(true);
            _productService.createProductAsync(
                product
            ).done(function () {
                abp.notify.info(app.localize('SavedSuccessfully'));
                _modalManager.close();
                abp.event.trigger('app.createProductModalSaved');
            }).always(function () {
                _modalManager.setBusy(false);
            });
        };
    };
    
})(jQuery);
